package com.chookss.home.myTest;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chookss.R;
import com.chookss.tiku.ExamResultActivitys;
import com.chookss.tools.NavigationTools;
import com.lvgroup.hospital.base.BaseAct;

import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import pl.droidsonroids.gif.GifDrawable;
import pl.droidsonroids.gif.GifImageView;

public class MyTestsDetailResultActivity extends BaseAct {
    @BindView(R.id.common_title_txt)
    TextView commonTitleTxt;
    @BindView(R.id.gif_view)
    GifImageView gifView;
    @BindView(R.id.tvInit)
    TextView tvInit;
    @BindView(R.id.llBottom)
    LinearLayout llBottom;
    private String recordType,examName,pmKey,examCode;
    private GifDrawable gifDrawable=null;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_tests_result);
        ButterKnife.bind(this);
        initState();
    }

    @Override
    public void initData() {
        NavigationTools.saveUseRecord(this,"1","05");
        recordType=getIntent().getStringExtra("recordType");
        examName=getIntent().getStringExtra("examName");
        pmKey=getIntent().getStringExtra("pmKey");
        examCode=getIntent().getStringExtra("examCode");
        commonTitleTxt.setText("交卷中");
        try {
            gifDrawable =  new GifDrawable(getResources(), R.drawable.jjz_jzgif);
            gifDrawable.setLoopCount(1);
            gifView.setBackground(gifDrawable);
            Observable.timer(gifDrawable.getDuration(), TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Consumer<Long>() {
                        @Override
                        public void accept(Long aLong) {
                            if(tvInit!=null){
                                if("3".equals(recordType)){
                                    tvInit.setText(getResources().getText(R.string.test_result2));
                                }else{
                                    tvInit.setText(getResources().getText(R.string.test_result));
                                }

                                llBottom.setVisibility(View.VISIBLE);
                            }
                        }
                    });
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @OnClick({R.id.common_title_back, R.id.tv1, R.id.tv2})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.common_title_back:
                finish();
                break;
            case R.id.tv1:
                finish();
                break;
            case R.id.tv2:
                Intent intent = new Intent(this, ExamResultActivitys.class);
                intent.putExtra("recordType",recordType);
                intent.putExtra("pmKey", pmKey);
                intent.putExtra("examCode", examCode);
                intent.putExtra("examName",examName);
                intent.putExtra("type", 1);
                startActivity(intent);
                finish();
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(gifDrawable!=null){
            gifDrawable.recycle();
        }
    }
}
